//	var province = <!--{echo json_encode($sites['openprovince'])}-->;
//    var city = <!--{echo json_encode($areas)}-->;
//    var thisCity = '{$thisCity}';
//  var thisProvince = '{$thisProvince}';
$(document).ready(function () {
    if (typeof thisProvince == 'undefined') {
        thisProvince = 0;
    }
    if (province) {
        for (var i in province) {
            var selected = '';
            if (thisProvince && thisProvince == province[i]['areaID']) {
                selected = 'selected';
            }
            jQuery("#province").append('<option value=' + province[i]['areaID'] + ' ' + selected + '>' + province[i]['prefix'] + ' ' + province[i]['areaName'] + '</option>');
        }
    }

    $("input.huxing_btn,.huxing_free_btn input,input.apart_huxing_btn,.apart_box img,.apart_info img").hover(function () {
        $(this).addClass('hover');
    }, function () {
        $(this).removeClass('hover');
    });

    $('.apart_box dl dd a,.apart_box dl dt a').hover(function () {
        $(this).find('strong').css('display', 'block');
    }, function () {
        $(this).find('strong').css('display', 'none');
    });


    var province_id = $("#province").val();

    if (typeof thisCity == 'undefined') {
        thisCity = 0;
    }
    if (thisCity > 0) {
        var citylist = city[province_id];
        for (var i in citylist) {
            var selected = '';
            if (thisCity && thisCity == citylist[i]['areaID']) {
                selected = 'selected';
            }
            jQuery("#city").append('<option value=' + citylist[i]['areaID'] + ' ' + selected + '>' + citylist[i]['areaName'] + '</option>');
        }

        if (thisCity > 0) {
            get_city(thisCity, '', '#area');
        }
    } else if (province_id > 0) {
        get_city(province_id, '#city', '#area');
    }

    var city_id = $("#city").val();
    if (typeof(thisArea) != 'undefined' && thisArea > 0) {
        var citylist = city[city_id];

        for (var i in citylist) {
            var selected = '';
            if (thisArea && thisArea == citylist[i]['areaID']) {
                selected = 'selected';
            }
            jQuery("#area").append('<option value=' + citylist[i]['areaID'] + ' ' + selected + '>' + citylist[i]['areaName'] + '</option>');
        }

    }


    $('#province').bind('change', function () {
        if ($(this).val()) {
            get_city($(this).val(), '#city', '#area');
        }
    });

    $('#city').bind('change', function () {
        if ($(this).val()) {
            get_city($(this).val(), '', '#area');
        }
    });
});
function get_city(pid, obj, child) {
    if (pid) {
        if (obj) $(obj).html("<option value=''>市/地区</option>");
        if (child) $(child).html(" <option value=''>区/县</option>");

        if (obj) {
            var citylist = city[pid];
            if (citylist) {
                $(obj).css('display', '');
                for (var i in citylist) {
                    $(obj).append('<option value=' + citylist[i]['areaID'] + '>' + citylist[i]['areaName'] + '</option>');
                }
            } else {
                $(obj).css('display', 'none');
            }
            if (child) {
                $(child).css('display', 'none');
            }
        } else if (child) {
            var citylist = city[pid];
            if (citylist) {
                $(child).css('display', '');
                for (var i in citylist) {
                    $(child).append('<option value=' + citylist[i]['areaID'] + '>' + citylist[i]['areaName'] + '</option>');
                }
            } else {
                $(child).css('display', 'none');
            }
        }

    }


}

